import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
const Timestamp = new Date().getTime() // 随机时间戳

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [vue(), vueJsx({
        include: ['.jsx', '.vue']
    })],
    resolve: {
        extensions: ['.jsx', '.js', '.vue'],
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    server: {
        // port: 80,  // 设置服务器端口号
        open: true, // 启动后打开
        hmr: true, // 开启热更新
        // cors: true, //允许跨域
        proxy: {
            '/test-api': {
                // target: 'http://10.152.164.84:8080',
                target: 'http://xone-txgw1.test.xdf.cn/dev-practice-ielts-4411',
                // target: 'http://xone-gw2.test.xdf.cn/dev-practice-ielts-4411/',
                // target: 'https://bjielts-t.test.xdf.cn', // 测试环境
                changeOrigin: true,
                secure: false,
                rewrite: (path) => path.replace('/test-api', ' ')
            }
        }
    },
    build: {
        sourcemap: false, // 输出.map文件,默认是false
        rollupOptions: {
            output: {
                chunkFileNames: `static/js/[name].[hash]${Timestamp}.js`,
                entryFileNames: `static/js/[name].[hash]${Timestamp}.js`,
                assetFileNames: `static/[ext]/[name].[hash]${Timestamp}.[ext]`
            }
        }
    }
})
